<?php

$searchparam1 = $_POST["search1"];
$searchparam2 = $_POST["search2"];
$searchopt = $_POST["searchopt"];
$sortopt = $_POST["sortopt"];
include 'dbconnect.php';

switch($searchopt)
{
	case "makemodel":
		$query = "SELECT * FROM VehicleForSale WHERE Make LIKE '$searchparam1' && Model LIKE '$searchparam2' ORDER BY '$sortopt' ASC";
		break;
	case "year":
		$query = "SELECT * FROM VehicleForSale WHERE VehicleYear LIKE '$searchparam1' ORDER BY '$sortopt' ASC";
		break;
	case "range":
		$query = "SELECT * FROM VehicleForSale WHERE PRICE >='$searchparam1' && Price <= '$searchparam2' ORDER BY '$sortopt' ASC";
		break;
}



$result = mysqli_query($mysql, $query);
if(!$result)
echo '<p>Query failed</p>';

while ($row = mysqli_fetch_assoc($result)) {
	$id = $row["VehicleForSaleID"];
	$imgName = $row["ImgName"];
	printf("<a href=\"download.php?id=%d&name=%s\">%s</a></br>", $id, $user_name, $imgName);
}
	



?>